/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [CalendarMain.java]
 * Creation Date        [10-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.calendar;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

/**
 * 万年历
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class CalendarMain extends JFrame implements ActionListener {

	private static final long serialVersionUID = 8266665825993635216L;

	private CalendarPanel calendarPanel = null;

	public CalendarMain() {
		calendarPanel = new CalendarPanel(this);
		getContentPane().add(calendarPanel);
		setTitle("日历");
		this.setLocation(500, 300);
		setResizable(false);
		pack();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("查看")) {
			// 如果点击查看按钮, 重新绘制日期
			calendarPanel.setTodayFlag(false);
			calendarPanel.displayDate();
		} else if (e.getActionCommand().equals("今天")) {
			// 点击今天按钮, 则将日期设置为今天
			calendarPanel.setTodayFlag(true);
			calendarPanel.setCalendarAsToday();
			calendarPanel.displayDate();
		}
	}

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				new CalendarMain();
			}
		});
	}

}